/*
 * <one line to give the program's name and a brief idea of what it does.>
 * Copyright (C) 2019
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "shipplayer.hpp"
#include "shippart.hpp"

ShipPlayer::ShipPlayer(const uint16_t weapon, const uint16_t reactor, const uint16_t hull, const uint16_t wings) {
	m_Hull = new ShipPart(upgradeType::HULL, hull);
	m_Reactor = new ShipPart(upgradeType::REACTOR, reactor);
	m_Weapon = new ShipPart(upgradeType::WEAPON, weapon);
	m_Wings = new ShipPart(upgradeType::WINGS, wings);
}

ShipPlayer::~ShipPlayer() {
	delete m_Weapon;
	delete m_Reactor;
	delete m_Hull;
	delete m_Wings;
}

void ShipPlayer::setShipPartLevel(const upgradeType type, const uint16_t level) {
	switch(type) {
		case upgradeType::HULL:
			m_Hull->setLevel(level);
			break;

		case upgradeType::WEAPON:
			m_Weapon->setLevel(level);
			break;

		case upgradeType::REACTOR:
			m_Reactor->setLevel(level);
			m_Data.shieldAbsorption = 1 + 0.02 * level;
			break;

		case upgradeType::WINGS:
			m_Wings->setLevel(level);
			break;
	}
}

double ShipPlayer::getShipPartValue(const upgradeType type) const {
	switch(type) {
		case upgradeType::HULL:
			return m_Hull->getValue();
			break;

		case upgradeType::WEAPON:
			return m_Weapon->getValue();
			break;

		case upgradeType::REACTOR:
			return m_Reactor->getValue();
			break;

		case upgradeType::WINGS:
			return m_Wings->getValue();
			break;
	}

	return 0.0;
}
double ShipPlayer::getDamage() const {
	return getShipPartValue(upgradeType::WEAPON);
}

double ShipPlayer::getHP() const {
	return getShipPartValue(upgradeType::HULL);
}

double ShipPlayer::getShield() const {
	return getShipPartValue(upgradeType::REACTOR);
}
double ShipPlayer::getShieldAbsorption() const {
	return 1 + m_Reactor->getLevel() * 0.02;
}

uint32_t ShipPlayer::getSpeed() const {
	return getShipPartValue(upgradeType::WINGS) * 100;
}

void ShipPlayer::reset() {
	m_Data = ShipData();
}
